Skip to content

VariantAnimationMixin

Sub classes

Name Children Inherits
VariantAnimation
prettyqt.core.variantanimation
Base class for animations.
PropertyAnimation
prettyqt.core.propertyanimation
Animates Qt properties.

Base classes

Name Children Inherits
AbstractAnimationMixin
prettyqt.core.abstractanimation
The base of all animations.

⋔ Inheritance diagram

graph TD
  2400666939["core.VariantAnimationMixin"]
  565069530["core.AbstractAnimationMixin"]
  3227531497["core.ObjectMixin"]
  2751680898["builtins.object"]
  565069530 --> 2400666939
  3227531497 --> 565069530
  2751680898 --> 3227531497

🛈 DocStrings

Bases: AbstractAnimationMixin

Source code in prettyqt/core/variantanimation.py
class VariantAnimationMixin(core.AbstractAnimationMixin):
    def __getitem__(self, value: float) -> datatypes.Variant:
        return self.keyValueAt(value)

    def __setitem__(self, key: float, value: datatypes.Variant):
        self.setKeyValueAt(key, value)

    def __iter__(self) -> Iterator[tuple[float, datatypes.Variant]]:
        return iter(self.keyValues())

    def set_easing(
        self,
        easing_type: (
            core.easingcurve.TypeStr | core.QEasingCurve.Type | Callable[[float], float]
        ),
    ):
        curve = core.EasingCurve()
        if callable(easing_type):
            curve.set_custom_type(easing_type)
        else:
            curve.set_type(easing_type)
        self.setEasingCurve(curve)

    def get_easing(self) -> core.easingcurve.TypeStr | Callable[[float], float]:
        curve = core.EasingCurve(self.easingCurve())
        typ = curve.get_type()
        return curve.get_custom_type() if typ == "custom" else typ

    def set_start_value(self, value: datatypes.Variant):
        self.setStartValue(value)

    def set_end_value(self, value: datatypes.Variant):
        self.setEndValue(value)

    def set_duration(self, duration: int):
        self.setDuration(duration)

    def set_range(self, start, end):
        self.setStartValue(start)
        self.setEndValue(end)

    def reverse(self):
        """True reverse instead of just setting direction."""
        self.setKeyValues(list(reversed(self.keyValues())))

    def reversed(self) -> VariantAnimation:
        """Return a reversed copy of the animation."""
        new = self.get_metaobject().copy(self)
        new.reverse()
        return new

    def append_reversed(self) -> Self:
        """Append the reversed animation, effectively doubling the duration."""
        self.setDuration(self.duration() * 2)
        first_part = [(k / 2, v) for k, v in self.keyValues()]
        second_part = [(1 - (k / 2), v) for k, v in self.keyValues()]
        keys = first_part + list(reversed(second_part))[1:]
        self.setKeyValues(keys)
        return self

append_reversed() -> Self

Append the reversed animation, effectively doubling the duration.

Source code in prettyqt/core/variantanimation.py
def append_reversed(self) -> Self:
    """Append the reversed animation, effectively doubling the duration."""
    self.setDuration(self.duration() * 2)
    first_part = [(k / 2, v) for k, v in self.keyValues()]
    second_part = [(1 - (k / 2), v) for k, v in self.keyValues()]
    keys = first_part + list(reversed(second_part))[1:]
    self.setKeyValues(keys)
    return self

reverse()

True reverse instead of just setting direction.

Source code in prettyqt/core/variantanimation.py
def reverse(self):
    """True reverse instead of just setting direction."""
    self.setKeyValues(list(reversed(self.keyValues())))

reversed() -> VariantAnimation

Return a reversed copy of the animation.

Source code in prettyqt/core/variantanimation.py
def reversed(self) -> VariantAnimation:
    """Return a reversed copy of the animation."""
    new = self.get_metaobject().copy(self)
    new.reverse()
    return new

:fa-brands-github: Show source on GitHub